n=[1,2,3,4,5]
arr=n[:]
resultStack=[]
def find(x):
    temp=-1
    if x==0:
        return temp
    for i in range(x+1,len(n)):
        if i in arr:
            return i
    return temp
def all_sort(n):
    global arr,resultStack
    while True:
        for i in arr:
            resultStack.append(i)
            arr.remove(i)
        if not len(resultStack)==len(n):
            continue
        print(resultStack)
        while find(resultStack[-1]):
            a=find(resultStack[-1])
            if not a==-1:
                resultStack[-1]=a
                for i in n:
                    if i not in resultStack and i not in arr:
                        arr.append(i)
                break
            else:
                resultStack.pop()
all_sort(n)